package org.mspring.mlog.action.admin;

import org.mspring.mlog.TabItem;
import org.mspring.mlog.entity.Weibo;
import org.mspring.mlog.service.WeiboService;
import org.mspring.nbee.orm.dao.sql.builder.part.condition.Operator;
import org.mspring.nbee.orm.dao.sql.builder.part.condition.SqlCondition;
import org.mspring.nbee.orm.dao.sql.pager.OrderType;
import org.mspring.nbee.orm.dao.sql.pager.PageResult;
import org.mspring.nbee.orm.dao.sql.pager.Pager;
import org.mspring.nbee.web.Action;
import org.mspring.nbee.web.support.QueryParam;
import org.mspring.nbee.web.support.WebContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author GaoYoubo
 * @since 2015/2/21
 */
@Action
@RequestMapping("/admin/weibo")
@TabItem(item = "100125")
public class WeiboAction extends BaseAdminAction {
    private WeiboService weiboService;

    @RequestMapping("/list")
    @TabItem(item = "100125005")
    public String list(WebContext context, Model model) {
        Pager pager = context.getPager();
        pager.addOrder("id", OrderType.DESC);
        List<SqlCondition> conditions = context.buildSqlConditions(
                model,
                new QueryParam("name", Operator.LIKE)
        );
        PageResult<Weibo> result = weiboService.list(conditions, pager);
        model.addAttribute("result", result);
        return "/admin/weibo/list";
    }

    @Autowired
    public void setWeiboService(WeiboService weiboService) {
        this.weiboService = weiboService;
    }
}
